#include <stdio.h>
int isInNumber(int n, int d){
    while(n>0){
        if(n % 10 == d)
            return 1;
        n = int(n/10);
    }
    return 0;
}

int main(){	
	int m,n,k;
	scanf("%d %d %d",&m,&n,&k);
	int count = 0;
	for (int t=m; t<=n; t++){
		if((t%k)==0 && isInNumber(t,k)==0) {
			count ++;
		}			
	} 	
	printf("%d",count);
} 
